#pragma once

extern "C"
{
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libavfilter/avfilter.h>
#include <libswscale/swscale.h>
#include <libavutil/opt.h>
#include <libavutil/time.h>
}

class RtmpPusher
{
private:
	RtmpPusher();

private: 
    int create_av_context(AVDictionary *options);
    int create_encoder();
    int create_decoder();
    int create_av_stream();
    int create_av_pack();
    int create_av_frame();

public:
    static RtmpPusher* GetInstance();

    int GetVideoIndex();

	int Init(const char* url);
	int Start();
	int Stop();

	int PushVideo(unsigned char* data, int size, int64_t pts);
	int PushAudio(unsigned char* data, int size, int64_t pts);

private:
    static RtmpPusher* m_pInstance;

private:
    int video_idx;
    char rtmp_url[256];

    //输入封装器
    AVFormatContext* _infmt_ctx;
    AVFormatContext* _outfmt_ctx;

    AVCodecContext* _encodec_ctx;
    AVCodecContext* _decodec_ctx;

    AVStream *out_stream;

    AVPacket enc_pkt;
    AVPacket *dec_pkt;

    struct SwsContext *img_convert_ctx;

    
    AVFrame *__frame, *__frame_yuv;
};